#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
int a[N], l[N], stk[N], top;

void solve() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		while (top && a[stk[top]] >= a[i]) top--;
		if (top) l[i] = a[stk[top]];
		else l[i] = -1;
		stk[++top] = i;
	}
	for (int i = 1; i <= n; i++) cout << l[i] << " ";
	cout << '\n';
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}